package com.xz.xzutils.module.xzmybatislogplus.socket;

/**
 * <p>
 * 拦截器是否启用通知
 * </p>
 *
 * @author DONG.WANG17@HAND-CHINA.COM
 * @since 2025/3/24-03-24 09:25
 */
public class InterceptorActiveNotice {
    private static InterceptorActiveNotice INSTANCE;
    private final SocketEndpoint client;

    private InterceptorActiveNotice(int activePort) {
        SocketConfig socketConfig = new SocketConfig(activePort);
        socketConfig.setCallback(new SocketCallback() {
            @Override
            public void onMessage(String message) {

            }

            @Override
            public void onError(Exception e) {

            }
        });
        this.client = SocketFactory.createClient(socketConfig);
        client.start();
    }

    public static InterceptorActiveNotice getInstance(int activePort) {
        if (null == INSTANCE) {
            INSTANCE = new InterceptorActiveNotice(activePort);
        }
        return INSTANCE;
    }

    public static void sendActiveNotice(boolean active) {
        if (active) {
            INSTANCE.client.sendData("ACTIVE:TRUE");
        } else {
            INSTANCE.client.sendData("ACTIVE:FALSE");
        }
    }
}
